package sg.edu.nus.iss.billing.service.subscription;

import java.util.Iterator;
import java.util.List;

import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.dao.subscription.SubscriptionDAO;
import sg.edu.nus.iss.billing.vo.subscription.MobileVoiceVO;
import sg.edu.nus.iss.billing.vo.subscription.SubscriptionVO;

public class MobileVoice extends Voice {

boolean canTerminate(String accountNo) {
		
		boolean result= true;
		SubscriptionDAO subscriptionDAO = new SubscriptionDAO();
		
		List<SubscriptionVO> subscribedPlanList=  subscriptionDAO.getSubscriptionForAcct(accountNo);
		for(Iterator<SubscriptionVO> subscribed = subscribedPlanList.iterator(); subscribed.hasNext(); ) {
			//Subscription Main Plan
			 SubscriptionVO subscribedPlan = subscribed.next();
	        if(subscribedPlan instanceof MobileVoiceVO)
	         {
	        	 MobileVoiceVO mobileVoiceVO = (MobileVoiceVO)subscribedPlan;
	        	 if(mobileVoiceVO.getStatus().equals(Util.ACCOUNT_STATUS_ACTIVE))
	        	 {
	        		//If start date if after the today date - 24 months
	        		 if(mobileVoiceVO.getStartDate().compareTo(Util.dateAddMonth(Util.getSystemDate(), -24))>0)
	        		 {
	        			 result = false;
	        			 break;
	        		 }
	        	 }
	         }
	        
	         
		}
		
		return result;
	}

}
